/**
 * @param {number} n
 * @return {string[]}
 */
 var generateParenthesis = function(n) {
    let result=[]
    recursion('',0,0);
    function recursion(str,left,right){
        if(left>n || left<right){
            return ;
        }
        if(str.length>=2*n){
            result.push(str);
            return ;
        }
        if(left>right){
            recursion(str+'(',left+1,right);
            recursion(str+')',left,right+1);
        }
        else{
            recursion(str+'(',left+1,right);
        }
    }
    return result;
};
console.log(generateParenthesis(2));